package com.yicong.ants.scenic

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.ViewModelStoreOwner


abstract class BaseFragment<T : ViewDataBinding> : Fragment() {
    protected lateinit var mBinding : T

    abstract fun setLayout(): Int

    override fun onCreateView(inflater: LayoutInflater,container: ViewGroup?,savedInstanceState: Bundle?): View? {
//        return super.onCreateView(inflater, container, savedInstanceState)
        val view = inflater.inflate(setLayout() ,container , false )
        mBinding = DataBindingUtil.bind(view)!!
        mBinding.lifecycleOwner = this
        return view
    }

    protected fun <V : ViewModel> initModel(modelClass: Class<V>): V {
        return ViewModelProvider(this)[modelClass]
    }

    protected fun <V : ViewModel> initModel(owner: ViewModelStoreOwner, modelClass: Class<V>): V {
        return ViewModelProvider(owner)[modelClass]
    }
}